﻿using System;
using System.Collections.Generic;


class Array18                   
{
    
    static void Main(string[] args)
    {
        Console.Write("Insert how long will be your array : ");
        int n = int.Parse(Console.ReadLine());
        int[] MyArray = new int[n];
        for (int i = 0; i < MyArray.Length; i++)
        {
            Console.Write("{0} : ", i + 1);
            MyArray[i] = int.Parse(Console.ReadLine());
        }
        int MaxCombination = (int)Math.Pow(2, MyArray.Length) - 1;
        int maxSubset = 0;
        string stringMaxSubset = "";
        for (int i = 1; i <= MaxCombination; i++)
        {
            List<int> TempList = new List<int>();
            int count = 0;
            for (int j = 0; j < MyArray.Length; j++)
            {

                int mask = 1 << j;
                int nAndMask = i & mask;
                int bit = nAndMask >> j;
                if (bit == 1)
                {
                    if (count == 0)
                    {
                        TempList.Add(MyArray[j]);
                        count++;
                        continue;
                    }
                    if (TempList[TempList.Count - 1] <= MyArray[j])
                    {
                        TempList.Add(MyArray[j]);
                        count++;
                    }
                    else
                    {
                        break;
                    }
                }
                if (count > maxSubset)
                {
                    maxSubset = count;
                    stringMaxSubset = "";
                    for (int h = 0; h < TempList.Count; h++)
                    {
                        stringMaxSubset += TempList[h] + " ";
                    }
                }

            }
        }
        Console.WriteLine("Longest subset in increasing order is {0}" , stringMaxSubset);

    }
    
}
